﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void btnTinh_Click(object sender, EventArgs e)
        {
            if (batNgoaiLe())
            {
                String soA = txtA.Text;
                String soB = txtB.Text;
                String phepTinh = null;
                if (cbPhepTinh.SelectedItem != null) phepTinh = cbPhepTinh.SelectedItem.ToString();
                int a = Int32.Parse(soA);
                int b = Int32.Parse(soB);
                if (phepTinh.Equals("Chia") && b == 0)
                {
                    MessageBox.Show("Khong chia duoc cho 0");
                }
                else
                {
                    if (phepTinh.Equals("Cộng"))
                    {
                        int kq = a + b;
                        txtKetQua.Text = kq.ToString();

                    }
                    else if (phepTinh.Equals("Trừ"))
                    {
                        int kq = a - b;
                        txtKetQua.Text = kq.ToString();
                    }
                    else if (phepTinh.Equals("Nhân"))
                    {
                        int kq = a * b;
                        txtKetQua.Text = kq.ToString();
                    }
                    else if (phepTinh.Equals("Chia"))
                    {
                        float kq = a / b;
                        txtKetQua.Text = kq.ToString();
                    }
                }
            }


        }
        public Boolean batNgoaiLe()
        {
            int x = 0;
            if (txtA.Text.Equals("") || txtB.Text.Equals(""))
            {
                MessageBox.Show("Chua Nhap");
                return false;
            }
            else if (Int32.TryParse(txtB.Text, out x) == false || Int32.TryParse(txtA.Text, out x) == false)
            {
                MessageBox.Show("Sai Kieu");
                return false;
            }
            return true;
        }
    }
}
